package com.egg.basic.fegin.fallback;

import com.egg.basic.fegin.BasicTestFeignClient;
import com.egg.basic.model.request.TestPost;
import com.egg.common.core.enums.ResponseCode;
import com.egg.common.core.model.response.ResponseData;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestBody;


/**
 * feignClient降级
 *
 * @author east
 */
@Slf4j
@Configuration
public class BasicTestFeignClientFallback implements FallbackFactory<BasicTestFeignClient> {


    @Override
    public BasicTestFeignClient create(Throwable cause) {
        return new BasicTestFeignClient() {

            @Override
            public ResponseData<Long> post(@RequestBody TestPost param) {
                ResponseData res = new ResponseData<>();
                res.setMsg(ResponseCode.FALLBACK_ERROR.getMessage());
                res.setCode(ResponseCode.FALLBACK_ERROR.getCode());
                return res;
            }

        };
    }


}